package com.wn.cl.park.controller;

import com.wn.cl.park.model.dto.PayRequest;
import com.wn.cl.park.service.IPaymentsService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yellow docker
 * @since 2025-03-11
 */
@RestController
@RequestMapping("/payments")
@Slf4j
public class PaymentsController {

    @Autowired
    private IPaymentsService paymentsService;



    /**
     * 支付接口
     *
     * @return 返回一个包含表单数据的HTML网页
     */
    @PostMapping("/pay")
    @ApiOperation("支付接口")
    public ResponseEntity<String> pay(@RequestBody PayRequest request) {
        String result = paymentsService.pay(request);
        return ResponseEntity.ok(result);
    }


    /**
     * 支付宝异步回调接口
     * http://内网穿透地址/order/notify
     */

    @PostMapping("/notify")
    public void aliPayNotify(HttpServletRequest request) {

        paymentsService.aliPayNotify(request);

    }

}
